package com.shenyong.serviceImpl;

import com.shenyong.entity.Article;
import com.shenyong.entity.Article_Kind;
import com.shenyong.entity.Collection;
import com.shenyong.entity.Comment;
import com.shenyong.exception.MyException;
import com.shenyong.mapper.QArticleMapper;
import com.shenyong.service.QArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Create by : qiang
 * GetData : 2019/12/10 8:29
 * 文件说明 ： ArticleServiceImpl
 */
@Service
public class QArticleServiceImpl implements QArticleService {
    @Autowired
    private QArticleMapper articleMapper;

    public int addArticle(Article article) {
        return articleMapper.addArticle(article);
    }

    public List<Article_Kind> selectAllArticle_Kind() {
        return articleMapper.selectAllArticle_Kind();
    }

    public List<Article> newHotArticle(Article article) {
        return articleMapper.newHotArticle(article);
    }

    public int addComment(Comment comment) {
        if (comment.getComment_userid() == 0) {
            throw new MyException("请登录");
        }
        if (comment.getComment_coumtent() == null || comment.getComment_coumtent() == "") {
            throw new MyException("评论内容不可为空");
        }
        comment.setComment_date(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return articleMapper.addComment(comment);
    }

    public Object artprev(Article article) {
        return articleMapper.artprev(article);
    }

    public Object artnext(Article article) {
        return articleMapper.artnext(article);
    }

    public int uppageView(Article article) {
        return articleMapper.uppageView(article);
    }
    public int upcollect(Collection collection){
        return articleMapper.upcollect(collection);
    }
    public int decollect(Collection collection){
        return articleMapper.decollect(collection);
    }

}
